<!--混凝土拌和站---动态监控--实时监控-->
<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-02 13:13:25
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-05-08 16:25:36
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        name="pitchManage_treeCheck"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left" style="width: 100%">
          <vDatePicker
            :defaultDate="value2"
            @selectPickDate="selectTime"
            width="215px !important"
          >
          </vDatePicker>
          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.stationId"
            placeholder="所有拌和站"
            @change="selectBhz"
          >
            <el-option
              v-for="v in bhzDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectBhz"
            v-model="getList.machineId"
            placeholder="所有拌和机"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in bhjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectCondition"
            v-model="getList.fConstructionhorizon"
            placeholder="施工层位"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in sgcDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectCondition"
            v-model="getList.warningLevel"
            placeholder="预警级别"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in yjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectCondition"
            v-model="getList.fCloseoperation"
            placeholder="闭合状态"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in CloseoperationDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.fMixturetype"
            placeholder="沥青混合料类型"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in liqhDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>
      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="listLoading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @openDialog="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          :info="queryCriteriaData"
          v-if="navigatepageNums > 1"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>

      <!--弹框 查看 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <commonPage
            :commonData="commonData"
            @loadingShow="loadingShow"
            @dialogShow="dialogShow"
            @searchForm="yj_searchForm(getList)"
            @dialogTitle="dialogTitles"
          >
          </commonPage>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
  
<script>
import vDatePicker from "@/components/public/v-DatePicker";

// import errorMonitoring from '@/components/pitchManage/dyMonitorManage/errorMonitoring';
// import publicForm from "@/components/public/el-form.vue"//弹框form
// import multiLevelTableData from '@/components/public/multiLevel-table';//主页面列表

import tree from "@/components/public/pitchManage_tree"; //左侧机构树
import TableData from "@/components/pitchManage/dyMonitorManage/el-tables"; //主页面列表
// import TableData from '@/components/HntManage/el-tables';//主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑

import commonPage from "@/components/pitchManage/dyMonitorManage/errorMonitoringPage"; //主页面列表

import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  // getClosedLists,//主页面列表接口
  getAsphaltClosedLists, //主页面列表接口
  // getClosedFormByParentId,//主页面列表详情接口
  // getStationmachineByfMachineid,//查询-拌合站信息-详情接口
  getStationmachineList, //拌合站列表
  // addClosedForm,//编辑保存
  // addAsphaltClosedForm,//编辑保存
  getMachineListByStationId, //拌合机
  getAsphaltRecipeListByCompanyId, // 查询-沥青混合料类型下拉框
  // getAsphaltClosedFormByParentId,//闭合-表单详情
} from "@/api/request.js";
import { statusType } from "@/utils/config"; //配置项
export default {
  name: "errorMonitoring",
  data() {
    return {
      name: "errorMonitoring", //按钮配置页面代号
      sgcDataList: formJs.sgcDataList, //施工层位
      yjDataList: formJs.yjDataList, //预警级别
      liqhDataList: [], //沥青混合料类型
      formData: {}, //新增编辑向后台传递对象
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {}, //分页
      djDataList: formJs.djDataList,
      CloseoperationDataList: formJs.CloseoperationDataList,
      bhzDataList: [], //拌合站
      bhjDataList: [], //拌合机
      value2: "", //主页面日期筛选绑定值
      // 列表配置项
      table_config: formJs.cbtable_config,
      tableData: [], //表格列表数据列表
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      showName: "未选择公司",
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", //拌合站
        machineId: "", //拌合机
        fConstructionhorizon: "", // 施工层位
        fMixturetype: "", //  沥青混合料类型
        warningLevel: "", // 预警等级
        fCloseoperation: "", //闭合状态
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
      },
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [], //树状图默认选中id
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      dialogTitle: "编辑",
      headerData: [],
      commonData: {}, //弹框组件页面数据
    };
  },
  components: {
    vDatePicker, //时间选择器
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    Pagination, //分页
    commonPage,
  },
  mounted() {
    this.table_config.thead[5]["callback"] = function (rowData) {
      let data = statusType[rowData.fWarninglevel];
      if (data) {
        return data.label;
      }
    };
    this.table_config.thead[5]["specialClass"] = function (rowData) {
      let data = statusType[rowData.fWarninglevel];
      if (data) {
        return data.className;
      }
    };
    this.table_config.operation.cols = [
      {
        lable: "",
        prop: "fCloseoperation",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];

    this.table_config.operation["specialClass"] = function (rowData) {
      var color = null;
      if (rowData == "未闭合") {
        color = "red !important";
      } else if (rowData == "已闭合") {
        color = "green !important";
      } else if (rowData == "无需闭合") {
        color = "#409eff !important";
      } else {
        color = "#000 !important";
      }
      return color;
    };

    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));

    if (JSON.parse(sessionStorage.getItem("pitchManage_getLists"))) {
      this.getList = JSON.parse(sessionStorage.getItem("pitchManage_getLists"));
      this.getbhjDataMethods(this.getList.stationId);
    }
    if (JSON.parse(sessionStorage.getItem("pitchManage_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("pitchManage_treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);
    this.getDate();
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },
    // 点击当前行
    rowChange() {
      // val
      // console.log(val);
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "3", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
              this.getList.fCompanyid = this.treeData[0].fCompanyid;
            } else {
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("pitchManage_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            this.mixingPlantList("3", this.getList);
            this.mixingPlantList("0", this.getList);
            this.getAsphaltRecipeListByCompanyId(this.getList.fCompanyid);
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      if (JSON.parse(sessionStorage.getItem("pitchManage_getLists"))) {
        this.getList = JSON.parse(
          sessionStorage.getItem("pitchManage_getLists")
        );
        this.getList.fCompanyid = data.fCompanyid;
        this.value2 = [this.getList.startDates, this.getList.endDates];
      } else {
        this.getList.fCompanyid = data.fCompanyid;
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.fConstructionhorizon = ""; // 施工层位
        this.getList.fMixturetype = ""; //  沥青混合料类型
        this.getList.warningLevel = ""; // 预警等级
        this.getList.fCloseoperation = ""; // 闭合状态
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.getList.page = 1;
      this.getAsphaltRecipeListByCompanyId(this.getList.fCompanyid); //沥青混合料类型
      this.mixingPlantList("0", this.getList);
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      window.sessionStorage.setItem(
        "pitchManage_getLists",
        JSON.stringify(data)
      );

      getAsphaltClosedLists(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            that.tableData = res.data.pageInfo.list;
            this.queryCriteriaData = res.data.pageInfo; //分页信息
            this.navigatepageNums =
              this.queryCriteriaData.navigatepageNums.length;
            // this.downloadExcel()
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 公共弹框loading是否显示
    loadingShow(e) {
      this.loadingEditDialog = e;
    },
    dialogShow(e) {
      this.dialogEditVisible = e;
    },
    dialogTitles(e) {
      this.dialogTitle = e;
    },
    // 查看
    yj_viewForm(row) {
      var id = row.fId;
      if (id != "" && id != null) {
        this.fId = row.fId;
        this.dialogEditVisible = true;
        this.loadingEditDialog = true;
        this.commonData = {
          data: row,
          companyId: this.getList.fCompanyid,
        };
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },

    // 获取拌合站数据
    mixingPlantList(num, datas) {
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "3", // 拌合站类型
      };

      this.bhzDataList = [];

      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            if (num == 0) {
              this.bhzDataList = [
                {
                  fItemName: "所有拌和站",
                  fItemValue: "",
                },
              ];
              arr.map((item) => {
                this.bhzDataList.push({
                  fItemName: item.fMachinename,
                  fItemValue: item.fMachineid,
                });
              });
            }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    getAsphaltRecipeListByCompanyId(id) {
      var data = {
        fCompanyid: id,
      };
      this.liqhDataList = [];
      getAsphaltRecipeListByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.asphaltRecipeList;
            this.liqhDataList = [
              {
                fItemName: "所有沥青混合料类型",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.liqhDataList.push({
                fItemName: item.fMixturetype,
                fItemValue: item.fMixturetype,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 拌合站选择
    selectBhz(e) {
      this.getList.machineId = "";
      this.getbhjDataMethods(e);
    },
    // 获取拌合机
    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 时间间隔
    // selectTime(e) {

    //     this.getList.startDates = e[0] + " " + "00:00:00"// 开始时间
    //     this.getList.endDates = e[1] + " " + "23:59:59"// 截至时间
    //     this.xlsxName = e[0] + '至' + e[1] + '混凝土拌和站记录数据'

    //     this.yj_searchForm(this.getList);
    // },
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
      this.yj_searchForm(this.getList);
    },

    getDate() {
      if (JSON.parse(sessionStorage.getItem("pitchManage_getLists"))) {
        this.getList = JSON.parse(
          sessionStorage.getItem("pitchManage_getLists")
        );
        this.getList.page = 1;
        this.value2 = [this.getList.startDates, this.getList.endDates];
        this.xlsxName =
          this.getList.startDates +
          "至" +
          this.getList.endDates +
          "混凝土拌和站记录数据";
      } else {
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间

        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
        this.xlsxName =
          this.common.getDay(-6) +
          "至" +
          this.common.getDay(0) +
          " " +
          "23:59:59" +
          "混凝土拌和站记录数据";
      }
    },

    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>
  
<style scoped lang="less">
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  // overflow-y: auto;
  display: flex;
  flex-direction: column;

  .jpbox {
    height: 100%;
  }

  .dialogBody {
    position: relative;
  }

  .tab {
    display: flex;
    font-size: 14px;
    height: 30px;
    line-height: 30px;
    box-sizing: border-box;
    border-bottom: 2px solid #e4e7ed;
    padding: 0 0.16rem;

    .btn {
      margin-top: 4px;
      margin-right: 16px;
      width: 102px;
      height: 24px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-top-right-radius: 4px;
      border-top-left-radius: 4px;
    }
  }

  .charts {
    // height: calc(100% - 30px);
    height: 620px;
  }
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.materialClass /deep/.el-table tr:nth-child(4) {
  display: none;
}

.jipeiBox {
  display: flex;
  flex: 1;

  .left {
    width: 60%;
    margin-right: 15px;
    display: flex;
    flex-direction: column;

    .errorMonitoring {
      flex: 1;
    }
  }

  .right {
    width: 40%;

    display: flex;
    flex-direction: column;

    .errorMonitoring {
      flex: 1;
      box-sizing: border-box;
      display: flex;
      justify-content: center;
      align-items: center;

      .tableWaring {
        width: 90%;
        height: 85%;
        margin: 15px;
        box-sizing: border-box;

        display: flex;
        flex-direction: column;
        align-content: space-around;
        border: 1px solid #ebeef5;
        border-bottom: none;

        .line {
          flex: 1;
          display: flex;
          line-height: 20px;
          // height: 25px;
          // line-height: 25px;
          border-bottom: 1px solid #ebeef5;

          .tableName {
            width: 40%;
            display: flex;
            justify-content: center;
            align-items: center;
            border-right: 1px solid #ebeef5;
          }

          .tableData {
            width: 55%;
            padding-left: 8px;
          }
        }

        .line:nth-child(2n) {
          background: #dbe7f5;
          color: #4f6375;
        }
      }
    }
  }
}
</style>